package com.brainardphotography.blog.web;

import com.brainardphotography.blog.BlogEntry;
import com.brainardphotography.blog.dao.BlogEntryDAO;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.google.sitebricks.At;
import com.google.sitebricks.Show;
import com.google.sitebricks.http.Get;

@At("/entry/:id")
@Show("Entry.html")
public class Entry extends BasePage {
	private static final long serialVersionUID = 8792601259417050659L;

	private BlogEntry blogEntry;
	private BlogEntry previousEntry;
	private BlogEntry nextEntry;

	@Inject
	private BlogEntryDAO entryDAO;

	public BlogEntry getBlogEntry() {
		return blogEntry;
	}

	public void setEntry(BlogEntry entry) {
		this.blogEntry = entry;
	}

	public BlogEntry getPreviousEntry() {
		return previousEntry;
	}
	
	public BlogEntry getNextEntry() {
		return nextEntry;
	}

	@Get
	public void get(@Named("id") String id) {
		blogEntry = entryDAO.get(id);
		previousEntry = entryDAO.getPreviousEntry(blogEntry);
		nextEntry = entryDAO.getNextEntry(blogEntry);
	}
}
